Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

460
Views
Receiving [Ljava.lang.Object in Apps Script (bringing attachment name from Gmail to Sheets)

Have been working on an Apps Script to bring Gmail message information (sender, subject, link, attachment) into a Google Sheet, but not able to bring the title of the attachment over successfully (attachment name field in Google Sheet reads like [Ljava.lang.Object;@127afe9; it appears to be related to the attachments array, but I cannot figure it out. Have tried the solutions offered in What does "[Ljava.lang.Object;@" mean?, but no luck.

function emailToSheet() {
  var label = GmailApp.getUserLabelByName('New TODO'); // Find messages with label
  var changeLabel = GmailApp.getUserLabelByName('TODO'); // Change message label to
  var ss = SpreadsheetApp.openById('xxxx'); // Append to spreadsheet
  var sh = ss.getSheetByName("Email"); //On this sheet

  var threads = label.getThreads();
  for (var i=0; i<threads.length; i++){

    var messages = threads[i].getMessages();
    for (var j=0; j<messages.length; j++)  {

      var sent = messages[j].getDate();
      var from = messages[j].getFrom();
      var subject = messages[j].getSubject();

      // Get attachment name
      var attachments = messages[j].getAttachments();
      var attachmentName = [];
      for (var k=0; k<attachments.length; k++) {
        var attachmentName = attachments[k].getName();
      }

      var messageId = messages[j].getId();
      var messageUrl = "https://mail.google.com/mail/u/0/#inbox/" + messageId;

      ss.appendRow([sent, from, subject, attachmentName, messageUrl])
    }
    threads[i].removeLabel(label);
    threads[i].addLabel(changeLabel);
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'm thinking that you want this:

  var attachmentName = [];
  for (var k=0; k<attachments.length; k++) {
    var attachmentName = attachments[k].getName();
  }

to be this:

   var attachmentName = [];
  for (var k=0; k<attachments.length; k++) {
    attachmentName.push(attachments[k].getName());
  }

and maybe this:

  ss.appendRow([sent, from, subject, attachmentName, messageUrl])

to be this:

  ss.appendRow([sent, from, subject, attachmentName.join(" "), messageUrl])
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!